package sonet.textui.agents;

import static ist.po.ui.Dialog.IO;
import ist.po.ui.Command;
import ist.po.ui.DialogException;
import sonet.*;
import sonet.textui.*;

import java.io.IOException;
import java.util.*;



/**
 * Class for representing account creation.
 */
public class ShowAllAgents extends Command<BrowsingState> {
	/**
	 * @param bank
	 *            the target bank
	 */
	public ShowAllAgents(BrowsingState state) {
		super(false, MenuEntry.SHOW_ALL_AGENTS, state);
	}

	/**
	 * @see ist.po.ui.Command#execute()
	 */
	@Override
	public final void execute()  throws DialogException, IOException {
		Collection<Agent> agents = _receiver.sonet.getAgents();		
		for(Agent i : agents)printAgent(i);	
	}
	
	private void printAgent(Agent a){
		String s="";
		String t="|";
		
		switch( a.getType() ){
			case INDIVIDUAL:   s += Message.typePerson() + t; break;
			case ORGANIZATION:	s += Message.typeOrganization() + t; break;
		}
		s += a.getIdentifier()+t;
		s += a.getName()+t;
		s += a.getEmail()+t;
		s += a.getPublications().size()+t;
		s += a.getInbox().size()+t;
		s += a.getOutbox().size()+t;
		s += a.getConnections().size()+t;
		switch( a.getAgentStatus()){
			case ACTIVE:		s += Message.agentActive(); break;
			case INACTIVE:		s += Message.agentInactive(); break;
		}		
		IO.println(s);	
	}
}